<?php

 class Setor {

     public
             function getTodosSetor( $pdo ) {
         $obj = $pdo->prepare( "SELECT
                                                            idsetor,
                                                            nomesetor
                                                    FROM
                                                            setor
                                                    ORDER BY
                                                            nomesetor ASC
                                                    " );

         return ($obj->execute()) ? $obj->fetchAll( PDO::FETCH_ASSOC ) : false;
     }

     public
             function getSetorId( $pdo, $idsetor ) {
         $obj = $pdo->prepare( "SELECT
                                                            idsetor,
                                                            nomesetor
                                                            
                                                            
                                                    FROM
                                                            setor
                                                    WHERE
                                                            idsetor = :idsetor
                                                    " );

         $obj->bindParam( ":idsetor", $idsetor );
         return ($obj->execute()) ? $obj->fetch( PDO::FETCH_ASSOC ) : false;
     }

     public
             function alteraDadosSetor( $pdo, $idsetor, $nomesetor ) {

         $sql = "UPDATE
                                            setor
                                    SET
                                            nomesetor=:nome
                                    WHERE
                                            idsetor=:idsetor";
         $obj = $pdo->prepare( $sql );
         $obj->bindParam( ":idsetor", $idsetor );

         $obj->bindParam( ":nome", $nomesetor );
         $obj->execute();
         return ($obj) ? $obj : false;
     }

     public
             function cadastrarSetor( $pdo, $nome ) {
         $sql = "INSERT INTO setor (nomesetor) VALUES (:nome)";
         $ins = $pdo->prepare( $sql );
         $ins->bindParam( ":nome", $nome );

         $obj = $ins->execute();

         return ($obj) ? $obj : false;
     }

     public
             function excluirSetor( $pdo, $idsetor ) {
         $ins = $pdo->prepare( "DELETE FROM
                                                            setor
                                                     WHERE
                                                            idsetor=:idusuario" );
         $ins->bindParam( ":idusuario", $idsetor );

         $obj = $ins->execute();

         return ($obj) ? $obj : false;
     }

 }
 